/**
 ****************************************************************************************************
 * @file        my_2D_draw.h
 * @author      嵌入式小书虫
 * @version     V1.0
 * @date        2020-04-17
 * @brief       my2d绘制函数
 ****************************************************************************************************
 *
 * 修改说明
 * V1.0 20200417
 * 第一次发布
 <欢迎关注微信公众号：嵌入式小书虫>
 *
 ****************************************************************************************************
 */

#ifndef _MY_2D_DRAW_H
#define _MY_2D_DRAW_H


#include "my_2D.h"

#include<string.h>
#ifndef MAX
#   define MAX(a,b)	((a) > (b) ? (a) : (b))
#endif

#ifndef MIN
#   define MIN(a,b)	((a) < (b) ? (a) : (b))
#endif

/******************************************************************************************/
extern my2d_font_tile_t my2d_font;


bool my2d_is_point_inside_region( const my2d_region_t *ptRegion,
                                    const my2d_location_t *ptPoint);

bool my2d_region_intersect(   const my2d_region_t *ptRegionIn0,
                                const my2d_region_t *ptRegionIn1,
                                my2d_region_t *ptRegionOut);
                                
my2d_fsm_rt_t my2d_fill_colour( const my2d_region_t * ptRegion,
                                        uint_fast16_t hwColour);

my2d_fsm_rt_t my2d_rgb565_fill_colour_with_opacity( 
                                               
                                                const my2d_region_t *ptRegion,
                                                uint16_t tColour,
                                                uint_fast8_t chRatio);

my2d_fsm_rt_t my2dp_rgb16_tile_copy_only(  //my2d_op_cp_t *ptOP,
                                            const my2d_tile_t *ptSource,
                                            //const my2d_tile_t *ptTarget,
                                            const my2d_region_t *ptRegion);  
my2d_fsm_rt_t my2dp_rgb16_tile_copy_keing(  //my2d_op_cp_t *ptOP,
                                            const my2d_tile_t *ptSource,
                                            //const my2d_tile_t *ptTarget,
                                            const my2d_region_t *ptRegion,
                                                uint16_t color); 

my2d_fsm_rt_t my2dp_rgb16_tile_copy_keing_Y_mirror_image(  const my2d_tile_t *ptSource,                                            
                                            const my2d_region_t *ptRegion,
                                                uint16_t color); 
my2d_fsm_rt_t my2dp_rgb16_tile_copy_keing_X_mirror_image(  const my2d_tile_t *ptSource,                                            
                                            const my2d_region_t *ptRegion,
                                                uint16_t color);  
my2d_fsm_rt_t my2dp_rgb16_tile_copy_keing_XY_mirror_image(  const my2d_tile_t *ptSource,                                            
                                            const my2d_region_t *ptRegion,
                                                uint16_t color);    
//=============================opacity========================================================================
my2d_fsm_rt_t my2dp_rgb16_tile_copy_only_and_opacity( const my2d_tile_t *ptSource,                                            
                                                const my2d_region_t *ptRegion,
                                                uint_fast8_t chRatio);  
my2d_fsm_rt_t my2dp_rgb16_tile_copy_keing_and_opacity(  const my2d_tile_t *ptSource,                                            
                                                const my2d_region_t *ptRegion,
                                                uint16_t color,
                                                uint_fast8_t chRatio);  
//================mask========================================================================== 
my2d_fsm_rt_t my2d_fill_colour_with_mask(const my2d_tile_t *ptSource,                                            
                                                const my2d_region_t *ptRegion,
                                                uint16_t color);  
                                                
my2d_fsm_rt_t my2d_fill_colour_with_mask2(const my2d_tile_t *ptSource,                                            
                                                const my2d_region_t *ptRegion,
                                                uint16_t color);                                                

my2d_fsm_rt_t my2d_fill_colour_with_mask_and_opacity(const my2d_tile_t *ptSource,                                            
                                                const my2d_region_t *ptRegion,
                                                uint16_t color,
                                                uint8_t chRatio);      
//=========================time_out=====================================================================
int64_t my2d_helper_get_system_timestamp(void);                                                
void s_tHelper_wMSUnit_init();  
bool my2d_helper_is_time_out(int64_t lPeriod, int64_t *plTimestamp);    

void calculate_fps_time(uint8_t type);
uint32_t get_fps_time();                                                
//================draw char========================================================================== 
my2d_fsm_rt_t my2dp_draw_point(my2d_location_t location,
                                uint16_t color); 
my2d_fsm_rt_t my2dp_draw_point_and_opacity(my2d_location_t location,
                                uint16_t color,
                                uint8_t chRatio);                                                
my2d_fsm_rt_t my2dp_draw_char( const char ch,                                            
                               const my2d_region_t *ptRegion);

extern const my2d_font_tile_t my2D_FONT_6x8;
extern const my2d_font_tile_t my2D_FONT_16x24;
int my2d_lcd_printf(const char *format, ...);
void my2d_lcd_text_location(uint8_t chY, uint8_t chX);
void my2d_set_lcd_text_font(my2d_font_tile_t font);
#endif
